package org.teiid.resource.adapter.cassandra;

import javax.resource.ResourceException;

import org.teiid.core.BundleUtil;
import org.teiid.resource.spi.BasicConnectionFactory;
import org.teiid.resource.spi.BasicManagedConnectionFactory;

/**
 * 
 * @author Kouba
 *
 */
public class CassandraManagedConnectionFactory extends BasicManagedConnectionFactory{

	private static final long serialVersionUID = 6467964324032304311L;
	private String adress;
	private String keyspace;
	
	public static final BundleUtil UTIL = BundleUtil.getBundleUtil(CassandraManagedConnectionFactory.class);
	
	@Override
	@SuppressWarnings("serial")
	public BasicConnectionFactory<CassandraConnectionImpl> createConnectionFactory() throws ResourceException {
		return new BasicConnectionFactory<CassandraConnectionImpl>() {
			@Override
			public CassandraConnectionImpl getConnection() throws ResourceException {
				return new CassandraConnectionImpl(CassandraManagedConnectionFactory.this);
			}
		};
	}

	public String getKeyspace() {
		return keyspace;
	}

	public void setKeyspace(String keyspace) {
		this.keyspace = keyspace;
	}

	public String getAdress() {
		return adress;
	}

	public void setAdress(String adress) {
		this.adress = adress;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((adress == null) ? 0 : adress.hashCode());
		result = prime * result
				+ ((keyspace == null) ? 0 : keyspace.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		CassandraManagedConnectionFactory other = (CassandraManagedConnectionFactory) obj;
		if (adress == null) {
			if (other.adress != null)
				return false;
		} else if (!adress.equals(other.adress))
			return false;
		if (keyspace == null) {
			if (other.keyspace != null)
				return false;
		} else if (!keyspace.equals(other.keyspace))
			return false;
		return true;
	}

	
}
